/**
 *@brief	�û���һЩ��ݽṹ���Լ���ɺ�ɾ����������뷽�� 
 *@date		2015-12-14
 *@author	ikangtai-wangwei
 *@copyright iknagtai corp
 **/
#include"debugTest.h"
#include<time.h>
#include<stdio.h> 
bool printAllCycleUnit(cycleUnitDS cycleDataDS){
	
	cycleFlag *flag = initCycleFlag2();
	
	char psF[11]= {0}; 
	changeTMToString(cycleDataDS.cycleData+flag->menstruationStartForecast,psF);
	char psC[11] = {0};
	changeTMToString(cycleDataDS.cycleData+flag->menstruationStartConfirm,psC);
	char peF[11] = {0};
	changeTMToString(cycleDataDS.cycleData+flag->menstruationEndForecast,peF);
	char peC[11] = {0};
	 changeTMToString(cycleDataDS.cycleData+flag->menstruationEndConfirm,peC);
	char BBTDay[11] = {0};
	changeTMToString(cycleDataDS.cycleData+flag->BBTRiseDay,BBTDay);
	char peakDay[11] = {0};
	changeTMToString(cycleDataDS.cycleData+flag->peakDay,peakDay);
	char ovDForecast[11] = {0};
	changeTMToString(cycleDataDS.cycleData+flag->ovulationDayForecast,ovDForecast);
	
	char ovConf[11] = {0};
	changeTMToString(cycleDataDS.cycleData+flag->ovulationDayConfirm,ovConf);
	char ovRecord[11] = {0};
	changeTMToString(cycleDataDS.cycleData+flag->ovulationDayUserRecord,ovRecord);
	char ovBBTRise[11] = {0};
	changeTMToString(cycleDataDS.cycleData+flag->ovulationDayBBTRise,ovBBTRise);
	char ovFNextPS[11] = {0};
	changeTMToString(cycleDataDS.cycleData+flag->ovulationDayNextMenstruation,ovFNextPS);
	char fertWSF[11] = {0};
	changeTMToString(cycleDataDS.cycleData+flag->fertileWindowStartForecast,fertWSF);
	char fertWEF[11] = {0};
	changeTMToString(cycleDataDS.cycleData+flag->fertileWindowEndForecast,fertWEF);
	char fertWSC[11] = {0};
	changeTMToString(cycleDataDS.cycleData+flag->fertileWindowStartConfirm,fertWSC);
	char fertWEC[11] = {0};
	changeTMToString(cycleDataDS.cycleData+flag->fertileWindowEndConfirm,fertWEC);
	char danWSF[11] = {0};
	changeTMToString(cycleDataDS.cycleData+flag->dangerWindowStartForecast,danWSF);
	char danWEF[11] = {0};
	changeTMToString(cycleDataDS.cycleData+flag->dangerWindowEndForecast,danWEF);
	char danWSC[11] = {0};
	changeTMToString(cycleDataDS.cycleData+flag->dangerWindowStartConfirm,danWSC);
	char danWEC[11] = {0};
	changeTMToString(cycleDataDS.cycleData+flag->dangerWindowEndConfirm,danWEC);
	char nextPSF[11] = {0};
	changeTMToString(cycleDataDS.cycleData+flag->nextMenstruationStartForecast,nextPSF);
	char nextPEF[11] = {0};
	changeTMToString(cycleDataDS.cycleData+flag->nextMenstruationEndForecast,nextPEF);
	char nextOV[11] = {0};
	changeTMToString(cycleDataDS.cycleData+flag->nextOvulationDayForecast,nextOV);
	char nextFWS[11] = {0};
	changeTMToString(cycleDataDS.cycleData+flag->nextFertileWindowStartForecast,nextFWS);
	char nextFWE[11] = {0};
	changeTMToString(cycleDataDS.cycleData+flag->nextFertileWindowEndForecast,nextFWE);
	char nextDWS[11] = {0};
	changeTMToString(cycleDataDS.cycleData+flag->nextDangerWindowStartForecast,nextDWS);
	char nextDWE[11] = {0};
	changeTMToString(cycleDataDS.cycleData+flag->nextDangerWindowEndForecast,nextDWE);
/*	printf("print this cycle begin:-----------");
	printf("cycleNum:%d,psF:%s,peF:%s,psC:%s,peC:%s,BBTRise:%s,peakDay:%s,ovF:%s,ovC:%s,ovUserRecord:%s,ovUserBasis:%d,ovBBTRise:%s,ovFNextPS:%s,\n",cycleDataDS.cycleNumber,psF,
	peF,psC,peC,BBTDay,peakDay,ovDForecast,ovConf,ovRecord,cycleDataDS.ovulationDayUserRecordBasis,ovBBTRise,ovFNextPS);
	printf("fertWSF:%s,fertWEF%s,fertWSC:%s,fertWEC:%s,danWSF:%s,danWEF:%s,danWSC:%s,danWEC:%s,nextPSF:%s,nextPEF%s,nextOV:%s,nextFWS:%s,nextFWE:%s,nextDWS:%s,nextDWE:%s!!",
	fertWSF,fertWEF,fertWSC,fertWEC,danWSF,danWEF,danWSC,danWEC,nextPSF,nextPEF,nextOV,nextFWS,nextFWE,nextDWS,nextDWE);
	printf("-------------print this cycle end!");
*/	char string[20][20] = {0};
	strcpy(string[0],psF);
	strcpy(string[1],psC);
	strcpy(string[2],peF);
	strcpy(string[3],psF);
	strcpy(string[4],psF);
	strcpy(string[5],psF);
	strcpy(string[6],psF);
	strcpy(string[7],psF);
	strcpy(string[8],psF);
	strcpy(string[9],psF);
	char string2[480] = {0};
	char add[2]="\t";
	/*char addS2[][9]= {"cycleNO:","psF----:","peF----:","psC----:","peC----:","BBTRise:","peakDay:","ovDayF-:","ovDayC-:","ovUserR:","ovUserB:","ovBBTR:","ovFNePS:","fertWSF:",
	"fertWEF:","fertWSC:","fertWEC:","danWSF:","danWEF:","danWSC:","danWEC:","nextPSF:","nextPEF","nextOV:","nextFWS:","nextFWE:","nextDWS:","nextDWE:"};
	char addS[][9]= {"","","","","","","","","","","","","","",
	"","","","","","","","","","","","","",""};
	*/
	char n[2] = {0};
	changeNumToChar(cycleDataDS.cycleNumber,n);
//	strcat(string2,addS[0]);
	strcat(string2,n);
	strcat(string2,add);
	
	
//	strcat(string2,addS[1]);
	strcat(string2,psF);
	strcat(string2,add);
	
//	strcat(string2,addS[2]);
	strcat(string2,peF);
	strcat(string2,add);
	
//	strcat(string2,addS[3]);
	strcat(string2,psC);
	strcat(string2,add);
	
//	strcat(string2,addS[4]);
	strcat(string2,peC);
	strcat(string2,add);
	
//	strcat(string2,addS[5]);
	strcat(string2,ovBBTRise);
	strcat(string2,add);
	
//	strcat(string2,addS[6]);
	strcat(string2,peakDay);
	strcat(string2,add);
	
//	strcat(string2,addS[7]);
	strcat(string2,ovDForecast);
	strcat(string2,add);
	
//	strcat(string2,addS[8]);
	strcat(string2,ovConf);
	strcat(string2,add);
	
//	strcat(string2,addS[9]);
	strcat(string2,ovRecord);
	strcat(string2,add);
//	char c[2] = {cycleDataDS.ovulationDayUserRecordBasis+'\0','\0'};
//	strcat(string2,addS[10]);
//	strcat(string2,c);
//	strcat(string2,add);
	
//	strcat(string2,addS[11]);
	strcat(string2,ovBBTRise);
	strcat(string2,add);
	
//	strcat(string2,addS[12]);
	strcat(string2,ovFNextPS);
	strcat(string2,add);
	
//	strcat(string2,addS[13]);
	strcat(string2,fertWSF);
	strcat(string2,add);
	
//	strcat(string2,addS[14]);
	strcat(string2,fertWEF);
	strcat(string2,add);
	
//	strcat(string2,addS[15]);
	strcat(string2,fertWSC);
	strcat(string2,add);
	
//	strcat(string2,addS[16]);
	strcat(string2,fertWEC);
	strcat(string2,add);
	
//	strcat(string2,addS[17]);
	strcat(string2,danWSF);
	strcat(string2,add);

//	strcat(string2,addS[18]);
	strcat(string2,danWEF);
	strcat(string2,add);
	
//	strcat(string2,addS[19]);
	strcat(string2,danWSC);
	strcat(string2,add);
	
//	strcat(string2,addS[20]);
	strcat(string2,danWEC);
	strcat(string2,add);
	
//	strcat(string2,addS[21]);
	strcat(string2,nextPSF);
	strcat(string2,add);
	
//	strcat(string2,addS[22]);
	strcat(string2,nextPEF);
	strcat(string2,add);
	
//	strcat(string2,addS[23]);
	strcat(string2,nextOV);
	strcat(string2,add);
	
///	strcat(string2,addS[24]);
	strcat(string2,nextFWS);
	strcat(string2,add);
	
//	strcat(string2,addS[25]);
	strcat(string2,nextFWE);
	strcat(string2,add);
	
//	strcat(string2,addS[26]);
	strcat(string2,nextDWS);
	strcat(string2,add);
	
//	strcat(string2,addS[27]);
	strcat(string2,nextDWE);
	strcat(string2,add);
	strcat(string2,"\n\n");
	
	printf("string ouput-->%s\n",string2);
	inputFileData(string2);
	return true;
}

bool printAllDayInputUnit(dayUnitDSInput dayData){
/*
	printf("date:%d/%d/%d,inCycle:%d,BBT:%.2f,menRecord:%d,cervRecord:%d,ovTest:%d,tempFlag:%d\n",
	(dayData.date)->tm_year,(dayData.date)->tm_mon,(dayData.date)->tm_mday,dayData.dayOfCycle,
	dayData.BBT,dayData.menstruationRecord,dayData.cervicalMunusRecord,dayData.ovulationTestResult,dayData.tempFlag);
*/
return true;
}

bool printAllDayOutputUnit(dayUnitDSOutput dayData){
/*
	printf("date:%d/%d/%d,inCycle:%d,peAcheF:%d,peAcheC:%d,pAvoidF:%d,pAvoidC:%d,hpMensEnd:%d,hpOv:%d,hpConcepChange:%.2f,hpNextMens:%d\n",
	(dayData.date)->tm_year+1900,(dayData.date)->tm_mon+1,(dayData.date)->tm_mday,dayData.dayOfCycle,
	dayData.periodAchieveForecast,dayData.periodAchieveConfirm,dayData.periodAvoidForecast,dayData.periodAvoidConfirm,dayData.homePageMenstruationEnd,
	dayData.homePageOvulation,dayData.homePageConceptionChance,dayData.homePageNextMenstruation);
*/
	char string[200]= {0};
	char date[11] = {0};
	changeTMToString(&(dayData.date),date);
	char dayOfCycle[3] = {0};
	char st[9][8]={"date--:","PAFoe-:","PACnf:","PAvoiF:","PAvoiC:","hpMenE:","hpOV--:","hpCong:","hpNeP:"};
	char add[2]="\t";	
	char periodAchieveForecast[3] = {0};changeNumToChar(dayData.periodAchieveForecast,periodAchieveForecast);
	char periodAchieveConfirm[3] = {0};changeNumToChar(dayData.periodAchieveConfirm,periodAchieveConfirm);
	char periodAvoidForecast[3] = {0};changeNumToChar(dayData.periodAvoidForecast,periodAvoidForecast);
	char periodAvoidConfirm[3] = {0};changeNumToChar(dayData.periodAvoidConfirm,periodAvoidConfirm);
	char homePageMenstruationEnd[3] = {0};changeNumToChar(dayData.homePageMenstruationEnd,homePageMenstruationEnd);
	char homePageOvulation[3] = {0};changeNumToChar(dayData.homePageOvulation,homePageOvulation);
	char homePageConceptionChance[3] = {0};changeNumToChar(dayData.homePageConceptionChance,homePageConceptionChance);
	char homePageNextMenstruation[3] = {0};changeNumToChar(dayData.homePageNextMenstruation,homePageNextMenstruation);
	
	strcat(string,st[0]);
	strcat(string,date);
	strcat(string,add);
	
	strcat(string,st[1]);
	strcat(string,periodAchieveForecast);
	strcat(string,add);
	
	strcat(string,st[2]);
	strcat(string,periodAchieveConfirm);
	strcat(string,add);
	
	
	strcat(string,st[3]);
	strcat(string,periodAvoidForecast);
	strcat(string,add);
	
	strcat(string,st[4]);
	strcat(string,periodAvoidConfirm);
	strcat(string,add);
	
	strcat(string,st[5]);
	strcat(string,homePageMenstruationEnd);
	strcat(string,add);
	
	strcat(string,st[6]);
	strcat(string,homePageOvulation);
	strcat(string,add);
	
	strcat(string,st[7]);
	strcat(string,homePageConceptionChance);
	strcat(string,add);
	
	strcat(string,st[8]);
	strcat(string,homePageNextMenstruation);
	strcat(string,add);
	strcat(string,"\n");
	inputFileData(string);
	
	return true;
	
}

bool printUserDataIntofile(userUnitDS userData){
	char string[200]= {0};
	char st[8][8]={"Vcount:","avPerL:","avCycL:","menErr:","cycErr:","avLuLe:","avOvDa:","abCase:"};
	char add[2]="\t";	
	char s1[3] = {0};changeNumToChar(userData.validCycleCount,s1);
	char s2[5] = {0};changeFloatToChar(userData.averageMenstruationLength,s2);
	char s3[5] = {0};changeFloatToChar(userData.averageCycleLength,s3);
	char s4[5] = {0};changeFloatToChar(userData.menstruationLengthError,s4);
	char s5[5] = {0};changeFloatToChar(userData.cycleLengthError,s5);
	char s6[5] = {0};changeFloatToChar(userData.averageLuteumPhaseLength,s6);
	char s7[5] = {0};changeFloatToChar(userData.averageOvulationDay,s7);
	char s8[3] = {0};changeNumToChar(userData.abnormalCaseAlert,s8);
	
	strcat(string,st[0]);
	strcat(string,s1);
	strcat(string,add);
		strcat(string,st[1]);
	strcat(string,s2);
	strcat(string,add);
		strcat(string,st[2]);
	strcat(string,s3);
	strcat(string,add);
		strcat(string,st[3]);
	strcat(string,s4);
	strcat(string,add);
		strcat(string,st[4]);
	strcat(string,s5);
	strcat(string,add);
		strcat(string,st[5]);
	strcat(string,s6);
	strcat(string,add);
		strcat(string,st[6]);
	strcat(string,s7);
	strcat(string,add);
		strcat(string,st[7]);
	strcat(string,s8);
	strcat(string,add);
	strcat(string,"\n");
	inputFileData(string);
	return true;
}

bool inputFileData(char *string){
	//char *fileLocation = "D:\\05 ����̩��Ŀ\\20 �㷨NEW\\test\\2.txt";
	char *fileLocation = "3.txt";
	FILE *file = fopen(fileLocation,"a+");
	if(file){
		int result =  fputs(string,file);
		if(result == 0){
			printf("data ALDayOutputList success!\n");
		}else{
			printf("data ALDayOutputList fail!\n");
		}
		fclose(file);
		return true;
	}
	return false;
	
}

bool changeNumToChar(int num,char *s){
	if(num < 100 && num >= 0){
		if(num < 10){
			s[0] = num+'0';
			return true;	
		} else{
			s[0] = num/10+'0';
			s[1] = num%10+'0';
			return true;
		}
	}
	return false;
}
//���ת����λС�� 
bool changeFloatToChar(float num,char *s){
	num *=100;
	int x = (int)num;
	int temp[4] = {0};
	temp[0] =x/1000%10;
	temp[1] =x/100%10;
	temp[2] =x/10%10;
	temp[3] =x%10;
	
	
	s[4] = temp[3]+'0';
	s[3] = temp[2]+'0';
	s[2] = '.';
	
	s[1] = temp[1]+'0';
	s[0] = temp[0]+'0';
	return true;
}


bool changeTMToString(time_t *timeS,char *string){ 
	if(time == NULL){
		return "NULL";
	}
	struct tm *time = gmtime(timeS);
	int year = time->tm_year+1900;
	char year4 = year / 1000+'0';
	char year3 = year / 100 % 10+'0';
	char year2 = year / 10 % 10 + '0';
	char year1 = year%10+'0';
	int mon = time->tm_mon+1;
	char mon2 = mon / 10 +'0';
	char mon1 = mon % 10 +'0';
	int day = time->tm_mday;
	char day2 = day / 10 +'0';
	char day1 = day % 10 +'0';	
	string[0] = year4;
	string[1] = year3;
	string[2] = year2;
	string[3] = year1;
	string[4] = '/';
	string[5] = mon2;
	string[6] = mon1;
	string[7] = '/';
	string[8] = day2;
	string[9]= day1;
	string[10]= '\0';
	
	
	return true;
}



int testAllInput(dayUnitDSInput *dayData,int inputCount,userUnitDS userData){
	int x = 0;
	int firstPS = 0;
	dayUnitDSOutput *dayOut = createDayOutputNum(500);
	cycleUnitDS *cycleOut = createCycleUnitNum(100);
	userUnitDS userDataNew;
	int cycleOutputLength = 0;
	int daysDataLength    = 0;
	int lastCycleIndex    = 0; 
	int lastPSIndex       = 0;
	int result = 0; 
	for(;x < inputCount; x++){
		if(dayData[x].menstruationRecord == 1 && firstPS == 0){
			//��⵽��һ�ξ��ڿ�ʼ
			inputFileData("use the firstInput!\n");
			 firstPS++;
			 result = theFirstUse(dayData[x].date, 4,33,3, 3,
				cycleOut+lastCycleIndex,&cycleOutputLength,dayOut,&daysDataLength,&userDataNew);
				lastCycleIndex+= 3;
				lastPSIndex = x;
			if(result == ERROR_CODE) return result; 
		}else if(dayData[x].menstruationRecord != 1 && dayData[x+1].menstruationRecord == 1){
			//�ҵ����¸����ڵı߽��
			inputFileData("inputBBT!\n");
			BBTInputTemp(dayData+lastPSIndex,x-lastPSIndex,cycleOut+lastCycleIndex,cycleOut+lastCycleIndex+4,&cycleOutputLength,
				dayOut,&daysDataLength,&userDataNew);
			lastCycleIndex+= 4; 
			if(result == ERROR_CODE) return result; 	
		}else if(dayData[x].menstruationRecord == 1 && firstPS!=0){
			//��ʱ������ͨ�ľ��ڿ�ʼ���� 
			inputFileData("input Period start!\n");
			periodInputStart(dayData[x].date,0,cycleOut+lastCycleIndex, cycleOut+lastCycleIndex+4,&cycleOutputLength,
				&userDataNew,dayOut,&daysDataLength);
			lastCycleIndex+= 4; 
			lastPSIndex = x;
			if(result == ERROR_CODE) return result; 
		}
		
	}
	cycleFlag *flag = initCycleFlag2();
	for(x = 0; x < lastCycleIndex+3; x++){
		//print:cycleNo, forecastPS - ConfirmPS , forecastOV - ConfirmOV
		if(cycleOut[x].cycleNumber<userDataNew.validCycleCount+1){
			if(cycleOut[x].cycleData[flag->menstruationStartConfirm]>100){
				int psError = getDaysDiff(cycleOut[x].cycleData+flag->menstruationStartConfirm,cycleOut[x].cycleData+flag->menstruationStartForecast);
				psError = psError>0?psError:0-psError;
				int ovError = 0;
				if(cycleOut[x].cycleData[flag->ovulationDayNextMenstruation]>100){
					ovError = getDaysDiff(cycleOut[x].cycleData+flag->ovulationDayNextMenstruation,cycleOut[x].cycleData+flag->ovulationDayForecast);
				}
				ovError = ovError>0?ovError:0-ovError;
				
			}
		}
	}
	return result; 
}

bool printErrorRange(int cycleNum,int psError,int ovError){
	char *string;
	char s[3][3] = {"","",""};
	changeNumToChar(cycleNum,s[0]);
	changeNumToChar(psError,s[1]);
	changeNumToChar(ovError,s[2]);
	char add[2]="\t";
	strcat(string,s[0]);
	strcat(string,add);
	strcat(string,s[1]);
	strcat(string,add);
	strcat(string,s[2]);
	strcat(string,add);
	inputFileData_Range(string);
	return true;
}
bool inputFileData_Range(char *string){
	char *fileLocation = "D:\\05 ����̩��Ŀ\\20 �㷨NEW\\test\\al.txt";
	FILE *file = fopen(fileLocation,"a+");
	if(file){
		int result =  fputs(string,file);
		if(result == 0){
			printf("data ALDayOutputList success!\n");
		}else{
			printf("data ALDayOutputList fail!\n");
		}
		fclose(file);
		return true;
	}
	return false;
	
}

//this function is used to check the data input is legitimate
int filerFunc(int type,dayUnitDSInput* daysInput,int daysInputLength,cycleUnitDS *cycleInput,
			int cycleInputLength,userUnitDS* userData,long firstPS){
	//1451577600-->2016.1.1
	if(type == 1 && firstPS < 1451577600){
		//�ϴ��¾�ʱ�䲻�ܹ��ھ�Զ 
		return ERROR_CODE;
	}
	if(type != 1 && daysInputLength == 0){
		//���type������1��daysInputLength�Ͳ���Ϊ0 
		return ERROR_CODE;
	}
	if(type != 1){
		//�ж����е���ݵ����ںϷ��� 
		int filerDay = 0;
		//1325347200->2012-01-01 0:0:0
		for(; filerDay < daysInputLength; filerDay++){
			if(daysInput[filerDay].date < 1325347200){
				#ifdef TEST_ALL_PRINT
					printf("ALOUTPUT-----:ERROR filerFunc input days have wrong data index :%d\n",filerDay);
				#endif
				return ERROR_CODE;
			}
		}
		int filerCycle = 0;
		int abnormalCount = 0;
		cycleFlag* flag = initCycleFlag2();
		for(; filerCycle < cycleInputLength; filerCycle++){
			if((cycleInput[filerCycle].cycleData[flag->menstruationStartConfirm] < 1325347200) ||
				(cycleInput[filerCycle].cycleData[flag->menstruationStartForecast] < 1325347200)){
					#ifdef TEST_ALL_PRINT
					printf("ALOUTPUT-----:ERROR filerFunc input cycles have wrong data index :%d! the cycleNum %d:\n",
								filerCycle,cycleInput[filerCycle].cycleNumber);
					#endif
				abnormalCount++;
				if(abnormalCount > 1){
					#ifdef TEST_ALL_PRINT
					printf("ALOUTPUT-----:ERROR filerFunc too many abnormal count so must return ERROR Code;\n");
					#endif	
					return ERROR_CODE;
				}
				
			}
		}
		
	}
	
	return 1;	
}

int checkInputPS(dayUnitDSInput* daysInput,int daysInputLength,cycleUnitDS *cycleInput,int cycleInputLength,userUnitDS* userData){
	
	// check 1:if this input cycle is the last cycle
	if(cycleInput[0].cycleNumber != userData->validCycleCount+1){
		#ifdef TEST_ALL_PRINT
		printf("ALOUTPUT-----: periodInputStart error:input cycle is not the last cycle!\n");
		#endif	
		return ERROR_CODE;
	}
	cycleFlag* flag = initCycleFlag2();
	// check 2: if the input new ps is latter than the last cycle
	time_t psLast = cycleInput[0].cycleData[flag->menstruationStartConfirm] > 100 ? 
					cycleInput[0].cycleData[flag->menstruationStartConfirm]:
					cycleInput[0].cycleData[flag->menstruationStartForecast];
	int x = 0;
	for(; x < daysInputLength;x++){
		if(daysInput[x].menstruationRecord == 1){
			break;
		}
	}
	if(x == daysInputLength){
		#ifdef TEST_ALL_PRINT
		printf("ALOUTPUT-----: periodInputStart error:input daydata ps is not found!\n");
		#endif
		return ERROR_CODE;
	}
	time_t ps = daysInput[x].date;
	int diff = getDaysDiff(&psLast, &ps);
	if(diff < 0 || diff > 150){
		#ifdef TEST_ALL_PRINT
		printf("ALOUTPUT-----: periodInputStart error:input daydata is not latter than cycle,maybe this is change the old period!\n");
		#endif	
		return ERROR_CODE;
	
	}
	return 1;
}

int checkDeletePS(dayUnitDSInput* daysInput,int daysInputLength, cycleUnitDS *cycleInput,int cycleInputLength,userUnitDS* userData){
	// check 1:if this input cycle is the last cycle
	if(cycleInputLength != 2){
		#ifdef TEST_ALL_PRINT
		printf("ALOUTPUT-----: deletePS error:input cycle length is not 2!\n");
		#endif
		return ERROR_CODE;
	} 
	if(cycleInput[1].cycleNumber != userData->validCycleCount+1 || cycleInput[0].cycleNumber != userData->validCycleCount ){
		#ifdef TEST_ALL_PRINT
		printf("ALOUTPUT-----: deletePS error:input cycle is not the last cycle!\n");
		#endif	
		return ERROR_CODE;
	}
	int x = 0;
	for(; x < daysInputLength;x++){
		if(daysInput[x].menstruationRecord == 1){
			break;
		}
	}
	if(x == daysInputLength){
		#ifdef TEST_ALL_PRINT
		printf("ALOUTPUT-----: deletePS error:input daydata ps is not found!\n");
		#endif
		return ERROR_CODE;
	}
	time_t deletePS = daysInput[x].date;
	
	
	// check 2: if the input new ps is latter than the last cycle
	cycleFlag* flag = initCycleFlag2();
	time_t psLast = cycleInput[0].cycleData[flag->menstruationStartConfirm] > 100 ? 
					cycleInput[0].cycleData[flag->menstruationStartConfirm]:
					cycleInput[0].cycleData[flag->menstruationStartForecast];
	time_t psNow = cycleInput[1].cycleData[flag->menstruationStartConfirm];	
	int diff = getDaysDiff(&psNow, &deletePS);
	if(diff != 0 ){
		#ifdef TEST_ALL_PRINT
		printf("ALOUTPUT-----: deletePS error:input daydata ps is not equal to the last cycle\n");
		#endif	
		return ERROR_CODE;
	}
	int diff2 = getDaysDiff(&psLast,&deletePS);
	if(diff2 > 200 || diff2 < 15){
		#ifdef TEST_ALL_PRINT
		printf("ALOUTPUT-----: deletePS error:input daydata ps is too less later than the cycleInput[0] or too bigger than\n");
		#endif	
		return ERROR_CODE;
	}
	return 1;
}

int checkInputPE(dayUnitDSInput* daysInput,int daysInputLength,cycleUnitDS *cycleInput,
				int cycleInputLength,userUnitDS* userData){
	// check 1:if this input cycle is the last cycle
	if(cycleInput[0].cycleNumber != userData->validCycleCount+1){
		#ifdef TEST_ALL_PRINT
		printf("ALOUTPUT-----: inputPE error:input cycle is not the last cycle!\n");
		#endif	
		return ERROR_CODE;
	}
	
	int x = 0;
	for(; x < daysInputLength;x++){
		if(daysInput[x].menstruationRecord == 2){
			break;
		}
	}
	if(x == daysInputLength){
		#ifdef TEST_ALL_PRINT
		printf("ALOUTPUT-----: inputPE error:input daydata pe is not found!\n");
		#endif
		return ERROR_CODE;
	}
	time_t PE = daysInput[x].date;
	cycleFlag* flag = initCycleFlag2();
	// check 2: if the input new pe is latter than the last cycle
	time_t ps = cycleInput[0].cycleData[flag->menstruationStartConfirm];
	if(ps < 1325347200){
		#ifdef TEST_ALL_PRINT
		printf("ALOUTPUT-----: deletePE error:input cycle psconfirm is abnormal: %l!\n",ps);
		#endif	
		return ERROR_CODE;
	}
	int diff = getDaysDiff(&ps, &PE);
	if(diff < 0 || diff > 15){
		#ifdef TEST_ALL_PRINT
		printf("ALOUTPUT-----: inputPE error:input daydata pe is too latter than the ps or before the ps ->%d\n",diff);
		#endif	
		return ERROR_CODE;
	}
	
	return 1;
}


int checkDeletePE(dayUnitDSInput* daysInput,int daysInputLength, cycleUnitDS *cycleInput,int cycleInputLength,userUnitDS* userData){
	cycleFlag* flag = initCycleFlag2();
	// check 1:if this input cycle is the last cycle
	if(cycleInput[0].cycleNumber != userData->validCycleCount+1){
		#ifdef TEST_ALL_PRINT
		printf("ALOUTPUT-----: deletePE error:input cycle is not the last cycle!\n");
		#endif	
		return ERROR_CODE;
	}
	int x = 0;
	for(; x < daysInputLength;x++){
		if(daysInput[x].menstruationRecord == 2){
			break;
		}
	}
	if(x == daysInputLength){
		#ifdef TEST_ALL_PRINT
		printf("ALOUTPUT-----: deletePE error:input daydata pe is not found!\n");
		#endif
		return ERROR_CODE;
	}
	time_t deletePE = daysInput[x].date;
	// check 2: if the delete pe is exist in the last cycle
	time_t ps = cycleInput[0].cycleData[flag->menstruationStartConfirm];
	time_t peWrong = cycleInput[0].cycleData[flag->menstruationEndConfirm];
	if(ps < 1325347200){
		#ifdef TEST_ALL_PRINT
		printf("ALOUTPUT-----: deletePE error:input cycle psconfirm is abnormal: %l!\n",ps);
		#endif	
		return ERROR_CODE;
	}
	int diff = getDaysDiff(&ps, &deletePE);
	if(diff < 0 || diff > 15){
		#ifdef TEST_ALL_PRINT
		printf("ALOUTPUT-----: deletePE error:input daydata pe is too latter than the ps or before the ps ->%d\n",diff);
		#endif	
		return ERROR_CODE;
	}
	int diff2 = getDaysDiff(&deletePE,&peWrong);
	if(diff2 != 0){
		#ifdef TEST_ALL_PRINT
		printf("ALOUTPUT-----: deletePE error:input daydata pe is not equal to the pe before ->%d\n",diff2);
		#endif	
		return ERROR_CODE;
	}
	
	return 1;
}

int checkFixPS(dayUnitDSInput* daysInput,int daysInputLength,cycleUnitDS *cycleInput,int cycleInputLength,userUnitDS* userData){
	if(cycleInputLength != 2){
		#ifdef TEST_ALL_PRINT
		printf("ALOUTPUT-----: fixPS error:input cycle length is not 2!\n");
		#endif
		return ERROR_CODE;
	} 
	cycleFlag* flag = initCycleFlag2();
	if(cycleInput[1].cycleNumber != userData->validCycleCount+1 || cycleInput[0].cycleNumber != userData->validCycleCount ){
		#ifdef TEST_ALL_PRINT
		printf("ALOUTPUT-----: fixPS error:input cycle is not the last cycle!\n");
		#endif	
		return ERROR_CODE;
	}
	
	time_t psRight = 0;
	int x = 0;
	for(; x < daysInputLength; x++){
		if(daysInput[x].menstruationRecord == 1){
			psRight = daysInput[x].date;
			break;
		}
	}
	
	time_t psNow = cycleInput[1].cycleData[flag->menstruationStartConfirm];
	int diff = getDaysDiff(&psRight,&psNow);
	if(diff > 15 || diff < -15){
		#ifdef TEST_ALL_PRINT
		printf("ALOUTPUT-----: fixPS error:psright and cycleInput[1] is not the same cycle\n");
		#endif	
		return ERROR_CODE;
	}
	time_t psLast = cycleInput[0].cycleData[flag->menstruationStartConfirm] > 100 ? 
					cycleInput[0].cycleData[flag->menstruationStartConfirm]:
					cycleInput[0].cycleData[flag->menstruationStartForecast];
	int diff2 = getDaysDiff(&psLast,&psRight);
	if(diff2 > 200 || diff2 < 15){
		#ifdef TEST_ALL_PRINT
		printf("ALOUTPUT-----: fixPS error:input daydata ps is too less later than the cycleInput[0] or too bigger than\n");
		#endif	
		return ERROR_CODE;
	}
	return 1;
	
}

int checkInputVisualPs(time_t ps, cycleUnitDS *cycleInput,userUnitDS* userData){
	// check 1:if this input cycle is the last cycle
	cycleFlag* flag = initCycleFlag2();
	if(cycleInput[0].cycleNumber != userData->validCycleCount+1){
		#ifdef TEST_ALL_PRINT
		printf("ALOUTPUT-----: inputVisualPS error:input cycle is not the last cycle!\n");
		#endif	
		return ERROR_CODE;
	}
	// check 2: if the input new ps is latter than the last cycle
	time_t psLast = cycleInput[0].cycleData[flag->menstruationStartConfirm] > 100 ? 
					cycleInput[0].cycleData[flag->menstruationStartConfirm]:
					cycleInput[0].cycleData[flag->menstruationStartForecast];
	int diff = getDaysDiff(&psLast, &ps);
	if(diff < 0 || diff > 150){
		#ifdef TEST_ALL_PRINT
		printf("ALOUTPUT-----: inputVisualPS error:input daydata is not latter than cycle!\n");
		#endif	
		return ERROR_CODE;
	
	}
	return 1;	
}

int checkInputBBTRecordAndMocus(dayUnitDSInput* daysInput,int daysInputLength,cycleUnitDS *cycleInput,int cycleInputLength,userUnitDS* userData){
	cycleFlag* flag = initCycleFlag2();
	time_t firstBBTDate = daysInput[0].date;
	time_t ps = cycleInput[0].cycleData[flag->menstruationStartConfirm];
	int diff = getDaysDiff(&ps,&firstBBTDate);
	if(diff > 0){
		#ifdef TEST_ALL_PRINT
		printf("ALOUTPUT-----:InputBBTRecrd or mucus error:input daydata is before ps!\n");
		#endif
		return ERROR_CODE;
	}else if(diff > 100){
		#ifdef TEST_ALL_PRINT
		printf("ALOUTPUT-----:InputBBTRecord or mucus error:input daydata is too later than ps,so maybe cycle is selected wrong!\n");
		#endif
		return ERROR_CODE;
	}else{
		return 1;
	}
}


int checkInputPastPeriod(dayUnitDSInput* daysInput,int daysInputLength,cycleUnitDS *cycleInput,int cycleInputLength,userUnitDS* userData){
	cycleFlag* flag = initCycleFlag2();
	int x = 0;
	for(;x< daysInputLength;x++){
		if(daysInput[x].menstruationRecord == 255) break;
	} 
	if(x == daysInputLength){
		#ifdef TEST_ALL_PRINT
		printf("ALOUTPUT-----:inputPastPeriod error:input daydata ps is not find!\n");
		#endif	
		return ERROR_CODE;
	}
	time_t inputps =  daysInput[x].date;
	for(x = cycleInputLength-1; x>=0;x++){
		if(cycleInput[x].cycleNumber == userData->validCycleCount+1) break;
	}
	if(x <0){
		#ifdef TEST_ALL_PRINT
		printf("ALOUTPUT-----:inputPastPeriod error:input cycle is invalid\n");
		#endif
	}
	time_t psNow = cycleInput[x].cycleData[flag->menstruationStartConfirm];
	if(psNow < 1325347200){
		#ifdef TEST_ALL_PRINT
		printf("ALOUTPUT-----:inputPastPeriod error:input cycle psNow is too old \n");
		#endif
		return ERROR_CODE;
	}
	int diff = getDaysDiff(&inputps,&psNow);
	if(diff <= 15){
		#ifdef TEST_ALL_PRINT
		printf("ALOUTPUT-----:inputPastPeriod error:this inputps is close to now and should not use inputPastPeriod function \n");
		#endif
		return ERROR_CODE;
	}
	return 1;
}

int deletePastPs(dayUnitDSInput* daysInput,int daysInputLength,cycleUnitDS *cycleInput,int cycleInputLength,userUnitDS* userData){
	cycleFlag* flag = initCycleFlag2();
	int x = 0;
	for(;x< daysInputLength;x++){
		if(daysInput[x].menstruationRecord == 255) break;
	} 
	if(x == daysInputLength){
		#ifdef TEST_ALL_PRINT
		printf("ALOUTPUT-----:deletePastPeriod error:input daydata ps is not find!\n");
		#endif	
		return ERROR_CODE;
	}
	time_t inputps =  daysInput[x].date;
	for(x = cycleInputLength-1; x>=0;x++){
		if(cycleInput[x].cycleNumber == userData->validCycleCount+1) break;
	}
	if(x <0){
		#ifdef TEST_ALL_PRINT
		printf("ALOUTPUT-----:deletePastPeriod error:input cycle is invalid\n");
		#endif
	}
	time_t psNow = cycleInput[x].cycleData[flag->menstruationStartConfirm];
	if(psNow < 1325347200){
		#ifdef TEST_ALL_PRINT
		printf("ALOUTPUT-----:deletePastPeriod error:input cycle psNow is too old \n");
		#endif
		return ERROR_CODE;
	}
	int diff = getDaysDiff(&inputps,&psNow);
	if(diff <= 15){
		#ifdef TEST_ALL_PRINT
		printf("ALOUTPUT-----:deletePastPeriod error:this inputps is close to now and should not use deletePastPeriod function \n");
		#endif
		return ERROR_CODE;
	}
	return 1;
}

int checkInputDataIsRight(int type,dayUnitDSInput* daysInput,int daysInputLength,
			cycleUnitDS *cycleInput,int cycleInputLength,userUnitDS* userData,time_t firstInputPS){
	int result = ERROR_CODE;
	int result2 = filerFunc(type,daysInput,daysInputLength,cycleInput,cycleInputLength,userData,firstInputPS);
	if(result2 == ERROR_CODE) return result2;
	switch (type){
		case 1:
			result = 1;
			break;
		case 2:
			result = checkInputPS(daysInput,daysInputLength,cycleInput,cycleInputLength,userData);
			break;
		case 3:
			result = checkInputPE(daysInput,daysInputLength,cycleInput,cycleInputLength,userData);
			break;
		case 4:
			result = checkDeletePS(daysInput,daysInputLength,cycleInput,cycleInputLength,userData);
			break;
		case 5:
			result = checkDeletePE(daysInput,daysInputLength,cycleInput,cycleInputLength,userData);
			break;
		case 6:
			result = checkFixPS(daysInput,daysInputLength,cycleInput,cycleInputLength,userData);
			break;
		case 7:
			result = 1;
		//	result = checkInputPS(daysInput,daysInputLength,cycleInput,cycleInputLength,userData);
			break;
		case 8:
			result = 1;
		//	result = checkInputPS(daysInput,daysInputLength,cycleInput,cycleInputLength,userData);
			break;
		case 9:
			result = 1;
			break;
		case 10:
			break;
		case 11:
			result = checkInputBBTRecordAndMocus(daysInput,daysInputLength,cycleInput,cycleInputLength,userData);
			break;
		case 12:
			result = checkInputBBTRecordAndMocus(daysInput,daysInputLength,cycleInput,cycleInputLength,userData);
			break;
		case 13:
			result = checkInputBBTRecordAndMocus(daysInput,daysInputLength,cycleInput,cycleInputLength,userData);
			break;
		case 14:
			result = checkInputBBTRecordAndMocus(daysInput,daysInputLength,cycleInput,cycleInputLength,userData);
			break;
		case 15:
			break;
		case 16:
			break;
		case 17:
			break;
		case 18:
			break;
		case 19:
			break;
		case 20:
			break;
		case 21:
			result = checkInputPastPeriod(daysInput,daysInputLength,cycleInput,cycleInputLength,userData);
			break;
		case 22:
			result = deletePastPs(daysInput,daysInputLength,cycleInput,cycleInputLength,userData);
			break;
		case 23:
			result = 1;
			break;
		case 24:
			result = 1;
			break;
		case 25:
			break;
		case 26:
			break;
		case 27:
			break;
		case 102:
			result = 1;
			break;
	
	
	}
}
int checkDaysOutNormal(const dayUnitDSOutput* daysOutput,const int *daysOutputLength){
	int index = 1;
	//ȥ��ͷ�ͽ�β 
	for(;index < *daysOutputLength ;index++){
		if(!(daysOutput[index-1].homePageNextMenstruation- daysOutput[index].homePageNextMenstruation == 1)){
			if(daysOutput[index-1].homePageNextMenstruation != 1){
				return ERROR_CODE;
			}
		} 
	}
	return 1;
	
}

int checkCycleOutNormal(const cycleUnitDS *cyclesOutput,const int *cyclesOutputLength){
	int index = 1;
	cycleFlag* flag = initCycleFlag2();
	for(; index < *cyclesOutputLength; index++){
		if((cyclesOutput[index].cycleData[flag->menstruationStartConfirm] < 1325347200) ||
				(cyclesOutput[index].cycleData[flag->menstruationStartForecast] < 1325347200)){
			return ERROR_CODE;			
		}
		if((cyclesOutput[index].cycleData[flag->menstruationEndConfirm] < 1325347200) ||
				(cyclesOutput[index].cycleData[flag->menstruationEndForecast] < 1325347200)){
			return ERROR_CODE;			
		}
		time_t ps = cyclesOutput[index].cycleData[flag->menstruationStartConfirm]>1325347200?
					cyclesOutput[index].cycleData[flag->menstruationStartConfirm]:
					cyclesOutput[index].cycleData[flag->menstruationStartForecast];
		if(cyclesOutput[index].cycleData[flag->ovulationDayForecast] < ps){
			return ERROR_CODE;			
		}
		if(cyclesOutput[index].cycleData[flag->ovulationDayConfirm] > 1325347200 && 
			cyclesOutput[index].cycleData[flag->ovulationDayConfirm] < ps){
			return ERROR_CODE;				
		}
		
	}
	return 1;
	
	
}
//this function is used to check the output data is right or not
int checkOutputIsLegitimate(int type,long firstPS,dayUnitDSOutput* daysOutput,
				int *daysOutputLength,cycleUnitDS *cyclesOutput,int *cyclesOutputLength){
	if(type == 1){
		
	}
	else if(type == 2){
		
	}
	else if(type == 3){
		
	}
	else if(type == 4){
		
	}
	else if(type == 5){
		
	}
	else if(type == 6){
		
	}
	else if(type == 7){
		
	}
	else if(type == 8){
		
	}
	else if(type == 9){
		
	}
	else if(type == 10){
		
	}
	else if(type == 11){
		
	}
	else if(type == 12){
		
	}
	else if(type == 13){
		
	}
	else if(type == 14){
		
	}
	else if(type == 15){
		
	}
	else if(type == 16){
		
	}
	else if(type == 17){
		
	}
	else if(type == 18){
		
	}
	else if(type == 19){
		
	}
	else if(type == 20){
		
	}
	else if(type == 21){
		
	}
	else if(type == 22){
		
	}
	else if(type == 23){
		
	}
	else if(type == 24){
		
	}
	else if(type == 25){
		
	}
	else if(type == 26){
		
	}
	else if(type == 102){
		
	}				
}

int findAllPS(int type,dayUnitDSInput* daysInput,int daysInputLength,int *psIndex){
	int result = 0;
	int x = 0;
	int y = 0;
	int mensIndex[100] = {0};
	time_t mensDate[100] = {0};
	int mensLength = 0;
	int index = 0;
	int psMax = 200;
	if(type == 4 || type == FIXFUTURE){
		psMax = 300;
	}
	for(;x < daysInputLength; x++){
		if(daysInput[x].menstruationRecord > 0 && daysInput[x].menstruationRecord < psMax){
			mensIndex[index] = x;
			mensDate[index] = daysInput[x].date;
			index++;
		}
	}
	mensLength = index;
	//��һ�ֹ��ˣ����˳����еľ��ڿ�ʼ�;��ڽ��� 
	for(x = 0;x < mensLength ; x++){
		for(y=x+1; y < mensLength; y++ ){
			int diff = getDaysDiff(&(mensDate[x]),&(mensDate[y]));
			if(diff > MOST_PERIOD_LENGTH && diff < 150){
				psIndex[result] = mensIndex[x];
				result++;
				x = y-1;
				break;	
			}
		}
		if(y == mensLength){
			psIndex[result] = mensIndex[x];
			result++;
			break;
		}
	} 
 	#ifdef TEST_ALL_PRINT
	for(x = 0; x < daysInputLength; x++){
		printf("\nindex:%d    ments:%d\n",x,daysInput[x].menstruationRecord);
	}
	printf("the ps is below:\n");
	for(x = 0; x < result; x++){
		printf("\nindex:%d    ments:%d\n",psIndex[x],daysInput[psIndex[x]].menstruationRecord);
	}
	#endif
	return result;
}

int checkCycle(time_t *psArray,int psLength,cycleUnitDS *cycleInput,int cycleInputLength){
	//�Ƚ�Ҫע�⣺1��˳��Ҫ�ԣ�2����Ҫ��cycle���д��� 
	int index[30] = {0};
	int x = 0;
	int count = 0;
	for(; x < psLength; x++){
		int y = 0;
		for(; y < cycleInputLength; y++){
			int diff = getDaysDiff(psArray+x,&(cycleInput[y].cycleData[2]));
			if(diff == 0){
				index[count] = y;
				count++;
				break;
			}
		}
		if(y == cycleInputLength){
			return ERROR_CODE;
		}
	}
	
	for(x = 1;x < count; x++){
		if(index[x] - index[x-1] != 1){
			return ERROR_CODE;
		}
	}
	return 1; 
}
int checkAllPsHaveCycleConfirmPS(int type,dayUnitDSInput* daysInput,int daysInputLength,cycleUnitDS *cycleInput,int cycleInputLength){
	int y = 0;
	for(; y< cycleInputLength;y++){
		int z = 0;
		for(z = y+1; z < cycleInputLength; z++){
			if(cycleInput[y].cycleData[2] == cycleInput[z].cycleData[2]){
				return ERROR_CODE;
			}
		}
	}
	int psIndex[200] = {0};
	int psCount = findAllPS(type,daysInput,daysInputLength,psIndex);
	time_t psArray[30] = {0};
	int x = 0;
	for(; x<psCount; x++){
		psArray[x] = daysInput[psIndex[x]].date;
	}
	int result = checkCycle(psArray,psCount,cycleInput,cycleInputLength);
	return result;
}
// 1 ��ʾ��������������  2 ��ʾ�ǶԵ�ǰ���ڵ��޸�  3 ��ʾ�ǶԹ�ȥ���ڵ����� 
int findNewPSLocation(dayUnitDSInput* daysInput,int daysInputLength,time_t ps,
						cycleUnitDS *cycleInput,int cycleInputLength,int *changeLocation){
	int psIndex[200] = {0};
	int psCount = findAllPS(1,daysInput,daysInputLength,psIndex);
	int x = 0;
	int diff = getDaysDiff(&(daysInput[psIndex[psCount-1]].date),&ps);
	int count = 0;
	if(diff > 15){
		if(cycleInputLength == 1 && cycleInput[0].cycleData[2] > 100){
			*changeLocation = 0;
		}else{
			for(;count < cycleInputLength; count++){
				if(cycleInput[count].cycleData[2] < 100 ) break;
			}
			if(count == cycleInputLength && cycleInput[count-1].cycleData[2] > 100){
				*changeLocation = count-1;
			}else if(count < cycleInputLength && cycleInput[count].cycleData[2] < 100 && cycleInput[count-1].cycleData[2] > 100){
				*changeLocation = count-1;
			}
		}
		
		return 1;
	}else if(diff <= 15 && diff >= -15){
		if(cycleInputLength == 1 && cycleInput[0].cycleData[2] > 100){
			*changeLocation = 0;
		}else{
			for(;count < cycleInputLength; count++){
				if(cycleInput[count].cycleData[2] < 100 ) break;
			}
			if(count == cycleInputLength && cycleInput[count-1].cycleData[2] > 100){
				*changeLocation = count-1;
			}else if(count < cycleInputLength && cycleInput[count].cycleData[2] < 100 && cycleInput[count-1].cycleData[2] > 100){
				*changeLocation = count-1;
			}
		}
		
		return 2;
	}else {
		
		return 3;
	}
	return 0;
}

int findNewPELocation(dayUnitDSInput* daysInput,int daysInputLength,time_t pe,
						cycleUnitDS *cycleInput,int cycleInputLength,int *changeLocation){
	int psIndex[200] = {0};
	int psCount = findAllPS(1,daysInput,daysInputLength,psIndex);
	
	int diff = getDaysDiff(&(daysInput[psIndex[psCount-1]].date),&pe);
	int count = 0;
	if(diff < 15 && diff > 0){
		//˵���ǵ�ǰ���� 
		if(cycleInputLength == 1 && cycleInput[0].cycleData[3] > 100){
			//�޸ĵ�ǰ���ڵľ��ڽ��� 
			*changeLocation = 0;
			return 2; 
		}else{
			if(cycleInput[psCount-1].cycleData[3] > 100){
				//�޸ľ��ڽ��� 
				*changeLocation = psCount-1;
				return 2; 
			} else{
				//����һ�����ڽ��� 
				*changeLocation = psCount-1;
				return 1;	
			}
			
		}
	}else if(diff < -1){
		int x = 0;
		for(; x < psCount; x++){
			int diff = getDaysDiff(&(daysInput[psIndex[x]].date),&pe);
			if(diff > 0 && diff < 15){
				break;
			}
		}
		if(x == psCount){
			return 0;
		}else{
			daysInput[psIndex[x]].menstruationRecord = 255;
		}
		return 3;
	}else {
		return 0;
	}
	return 0;
}

int findOldPSLocation(dayUnitDSInput* daysInput,int daysInputLength,time_t ps,
						cycleUnitDS *cycleInput,int cycleInputLength,int *changeLocation){
	int psIndex[200] = {0};
	int psCount = findAllPS(4,daysInput,daysInputLength,psIndex);
	int x = 0;
	int diff = getDaysDiff(&ps, &(daysInput[psIndex[psCount-1]].date));
	int count = 0;
	if(diff == 0){
		if(cycleInputLength == 1 && cycleInput[0].cycleData[2] > 100){
			*changeLocation = 0;
		}else{
			for(;count < cycleInputLength; count++){
				if(cycleInput[count].cycleData[2] < 100 ) break;
			}
			if(count == cycleInputLength && cycleInput[count-1].cycleData[2] > 100){
				*changeLocation = count-1;
			}else if(count < cycleInputLength && cycleInput[count].cycleData[2] < 100 && cycleInput[count-1].cycleData[2] > 100){
				*changeLocation = count-1;
			}
		}
		
		return 1;
	}else{
		return 3;
	}
	return 0;
}

int findOldPELocation(dayUnitDSInput* daysInput,int daysInputLength,time_t pe,
						cycleUnitDS *cycleInput,int cycleInputLength,int *changeLocation){
	int psIndex[200] = {0};
	int x = 0;
	int count = 0;
	for(;count < cycleInputLength; count++){
		int diff = getDaysDiff(&pe,&(cycleInput[count].cycleData[3]));
		if(diff == 0){
			break;	
		}
	}
	if(count == cycleInputLength){
		return 0;
	}else{
		if(count == cycleInputLength-1){
			*changeLocation = count;
			return 1;
		}else{
			return 3;
		}
	}
	
	return 0;
}



